function t(t, a) {
    for (var e = 0, r = t.length; e < r; e++) for (var n = 0, s = a.array.length; n < s; n++) t[e] == a.array[n].work_date && (a.array[n].disabled = !0);
}

function a() {
    return new Date();
}

function e(t, a, e) {
    var n = [];
    t.setDate(1);
    var h = t.getDay(), i = t.getMonth(), o = t.getFullYear(), d = r(i + 1, o), u = function(t) {
        var a = new Date(), e = null;
        return 0 == t.month ? (a.setFullYear(t.year - 1), a.setMonth(11), a.setDate(r(12, t.year - 1)), 
        e = a.getDay(), {
            month: 12,
            year: t.year - 1,
            day: e,
            date: r(12, t.year - 1)
        }) : (a.setFullYear(t.year), a.setMonth(t.month - 1), a.setDate(r(t.month, t.year)), 
        e = a.getDay(), {
            month: t.month,
            year: t.year,
            day: e,
            date: r(t.month, t.year)
        });
    }({
        month: t.getMonth(),
        year: t.getFullYear()
    }), l = function(t) {
        var a = new Date(), e = null;
        return 11 == t.month ? (a.setFullYear(t.year + 1), a.setMonth(0), a.setDate(1), 
        e = a.getDay(), {
            month: 1,
            year: t.year + 1,
            day: e,
            date: 1
        }) : (a.setFullYear(t.year), a.setMonth(t.month + 1), a.setDate(1), e = a.getDay(), 
        {
            month: t.month + 2,
            year: t.year,
            day: e,
            date: 1
        });
    }({
        month: t.getMonth(),
        year: t.getFullYear()
    });
    if (0 == h) {
        var y = 42 - d;
        u.month += 1;
        for (var c = 0; c < d; c++) {
            var m = c < 9 ? "0" + (c + 1) : c + 1, D = i < 9 ? "0" + (i + 1) : i + 1;
            n.push({
                type: "current",
                date: m,
                month: D,
                year: o,
                work_date: o + "-" + D + "-" + m,
                overdue: s(o, i + 1, c + 1)
            });
        }
        for (var g = 0; g < y; g++) {
            var v = g < 9 ? "0" + (g + 1) : g + 1, f = l.month <= 9 ? "0" + l.month : l.month;
            n.push({
                type: "next",
                date: v,
                month: f,
                year: l.year,
                work_date: l.year + "-" + f + "-" + v,
                overdue: s(l.year, l.month, g + 1)
            });
        }
    } else {
        for (var p = u.date - h + 1; p < u.date + 1; p++) {
            var M = p, _ = u.month <= 9 ? "0" + u.month : u.month;
            n.push({
                type: "prev",
                date: M,
                month: _,
                year: u.year,
                work_date: u.year + "-" + _ + "-" + M,
                overdue: s(u.year, u.month, p)
            });
        }
        for (var w = 0; w < d; w++) {
            var L = w < 9 ? "0" + (w + 1) : w + 1, F = i < 9 ? "0" + (i + 1) : i + 1;
            n.push({
                type: "current",
                date: L,
                month: F,
                year: o,
                work_date: o + "-" + F + "-" + L,
                overdue: s(o, i + 1, w + 1)
            });
        }
        for (var Y = 0, x = 42 - n.length; Y < x; Y++) {
            var C = Y < 9 ? "0" + (Y + 1) : Y + 1, k = l.month <= 9 ? "0" + l.month : l.month;
            n.push({
                type: "next",
                date: C,
                month: k,
                year: l.year,
                work_date: l.year + "-" + k + "-" + C,
                overdue: s(l.year, l.month, Y + 1)
            });
        }
    }
    return "current" == e && a.setData({
        currentDateList: n,
        year: o,
        month: i,
        currentDate: o + "-" + (i + 1)
    }), {
        array: n,
        prev: u.year + "-" + (u.month <= 9 ? "0" + u.month : u.month) + "-" + n[0].date,
        next: l.year + "-" + (l.month <= 9 ? "0" + l.month : l.month) + "-" + n[41].date
    };
}

function r(t, a) {
    return h([ 4, 6, 9, 11 ], t) ? 30 : h([ 1, 3, 5, 7, 8, 10, 12 ], t) ? 31 : parseInt(a) % 4 == 0 || parseInt(a) % 400 == 0 ? 29 : 28;
}

function n() {
    var t = new Date();
    return t.setDate(1), t.getDay();
}

function s(t, a, e) {
    var r = new Date();
    return 3 == arguments.length ? t < r.getFullYear() || t == r.getFullYear() && (a < r.getMonth() + 1 || a == r.getMonth() + 1 && e <= r.getDate()) ? "once" : "futrue" : 2 == arguments.length ? t < r.getFullYear() || t == r.getFullYear() && a <= r.getMonth() + 1 ? "once" : "futrue" : void 0;
}

function h(t, a) {
    for (var e in t) if (t[e] === a) return !0;
    return !1;
}

Component({
    properties: {
        calendarEvents: {
            type: Array,
            value: []
        }
    },
    data: {
        datainfo: [],
        calendarEvent: [],
        preDateList: [],
        currentDateList: [],
        nextDateList: [],
        dataList: [],
        swiperCurrent: 0,
        year: "",
        month: "",
        currentDate: "",
        currentMonth: a().getFullYear() + "-" + (a().getMonth() + 1),
        current_date_id: a().getDate() - 1 + n(),
        selected_data_id: a().getDate() - 1 + n()
    },
    observers: {
        calendarEvents: function(t) {
            console.log(t), this.setData({
                datainfo: t
            });
        }
    },
    ready: function() {
        var t = new Date(), a = t.getMonth() + 1, e = t.getFullYear() + "-" + (a <= 9 ? "0" + a : a) + "-" + (t.getDate() <= 9 ? "0" + t.getDate() : t.getDate());
        this.setData({
            current_date_id: t.getFullYear() + "-" + (a <= 9 ? "0" + a : a) + "-" + (t.getDate() <= 9 ? "0" + t.getDate() : t.getDate()),
            selected_data_id: e
        }), this.triggerEvent("select", {
            work_date: e,
            disabled: this.data.datainfo.includes(e)
        }), this.setCurrentMonth("current"), this.setPreMonth("pre"), this.setNextMonth("next"), 
        this.setData({
            dataList: [ this.data.currentDateList, this.data.nextDateList, this.data.preDateList ]
        }), console.log(this.data.dataList);
    },
    methods: {
        changeDate: function(t) {
            this.setData({
                selected_data_id: t.currentTarget.dataset.index
            });
            var a = t.currentTarget.dataset.disabled || !1;
            this.triggerEvent("select", {
                work_date: t.currentTarget.dataset.index,
                disabled: a
            });
        },
        nextMonth: function() {
            var t = this.data.swiperCurrent, a = 2 == this.data.swiperCurrent ? 0 : this.data.swiperCurrent + 1;
            this.setData({
                swiperCurrent: a
            }), this.changeMonth(t, a);
        },
        preMonth: function() {
            var t = this.data.swiperCurrent, a = 0 == this.data.swiperCurrent ? 2 : this.data.swiperCurrent - 1;
            this.setData({
                swiperCurrent: a
            }), this.changeMonth(t, a);
        },
        changeMonth: function(t, a) {
            0 == a && 2 == t ? 11 == this.data.month ? (this.data.month = 0, this.data.year = this.data.year + 1) : this.data.month = this.data.month + 1 : 2 == a && 0 == t || t > a ? 0 == this.data.month ? (this.data.month = 11, 
            this.data.year = this.data.year - 1) : this.data.month = this.data.month - 1 : t < a && (11 == this.data.month ? (this.data.month = 0, 
            this.data.year = this.data.year + 1) : this.data.month = this.data.month + 1);
            var e = 0 == a ? 2 : a - 1, r = 2 == a ? 0 : a + 1, n = a;
            this.setIndexMonth("current"), this.setNextMonth("next"), this.setPreMonth("prev");
            var s = [];
            s[e] = this.data.preDateList, s[r] = this.data.nextDateList, s[n] = this.data.currentDateList, 
            this.setData({
                dataList: s
            });
        },
        swiperChangeMonth: function(t) {
            console.log(this.data.swiperCurrent), console.log(t.detail.current);
            var a = t.detail.current;
            this.changeMonth(this.data.swiperCurrent, a), this.data.swiperCurrent = a;
        },
        setCurrentMonth: function(r) {
            var n = a();
            this.setData({});
            var s = e(n, this, r);
            t(this.data.datainfo, s), console.log(s, this.data.datainfo), this.setData({
                currentDateList: s.array
            });
        },
        setIndexMonth: function(r) {
            var n = a();
            n.setMonth(this.data.month), n.setFullYear(this.data.year), this.setData({});
            var s = e(n, this, r);
            t(this.data.datainfo, s), console.log(s, this.data.datainfo), this.setData({
                currentDateList: s.array
            });
        },
        setPreMonth: function(t) {
            console.log(this.data);
            var a = new Date();
            0 == this.data.month ? (a.setMonth(11), a.setFullYear(this.data.year - 1)) : (a.setMonth(this.data.month - 1), 
            a.setFullYear(this.data.year));
            var r = e(a, this, t);
            this.data.preDateList = r.array;
        },
        setNextMonth: function(t) {
            var a = new Date();
            11 == this.data.month ? (a.setMonth(0), a.setFullYear(this.data.year + 1)) : (a.setMonth(this.data.month + 1), 
            a.setFullYear(this.data.year));
            var r = e(a, this, t);
            this.data.nextDateList = r.array;
        }
    }
}), t.judge = function(t, a, e) {
    0 == t.length ? e.setData({
        currentDateList: a.array,
        detail_content: "本月未写日记",
        off_time: "",
        detail_id: 0
    }) : e.setData({
        currentDateList: a.array,
        detail_content: null == a.array[e.data.date_id].content ? "当天没写日记" : a.array[e.data.date_id].content,
        off_time: null == a.array[e.data.date_id].off_time ? "" : a.array[e.data.date_id].off_time,
        detail_id: null == a.array[e.data.date_id].id ? 0 : a.array[e.data.date_id].id
    });
};